﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.Parameters
{
    public partial class academic_year : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("XNXQWH");
            strPageUserType.Add("mana");

            if (!IsPostBack)
            {
                InitBind();
            }
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btnAdd_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("AddacadmicYear.aspx");
        //}

        /// <summary>
        /// 页面初始化绑定
        /// </summary>
        protected void InitBind()
        {
            LabMS.BLL.Semester BS = new LabMS.BLL.Semester();
            gvSemester.DataSource = BS.GetAllList();
            gvSemester.DataBind();
        }

        protected void gvSemester_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSemester.PageIndex = e.NewPageIndex;
            InitBind();
        }

        protected void gvSemester_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
                e.Row.Attributes["style"] = "Cursor:pointer";

                if (e.Row.Cells.Count > 3)
                {
                    if (e.Row.Cells[2].Text == "1")
                    {
                        e.Row.Cells[2].Text = "春季学期";
                    }
                    else if (e.Row.Cells[2].Text == "2")
                    {
                        e.Row.Cells[2].Text = "秋季学期";
                    }
                }
            }
        }

        protected void gvSemester_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbEdit")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                //DataKey key = gvSemester.DataKeys[id];
                //int ID =int.Parse(key.Value.ToString());//取出ID
                Response.Redirect("Edit.aspx?ID="+id);
            }
            else if (e.CommandName == "lbDel")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                LabMS.BLL.Semester BS = new LabMS.BLL.Semester();
                try
                {
                    BS.Delete(id);
                    Common.JShelper.JSAlert(this.Page, "", "删除成功！");
                    InitBind();
                }
                catch
                {
                    Common.JShelper.JSAlert(this.Page, "", "删除失败！");
                }
            } 
        }
    }
}
